package com.biye.api.controller.admin;

import com.alibaba.fastjson.JSONObject;
import com.base.common.edu.entity.Department;
import com.biye.api.service.DepartmentService;
import io.swagger.annotations.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @Author Maple.Chen
 * @Description 部门表数据修改对外接口定义Controller (Rest风格，RESTful结构)
 * @Date 17:03 2021/2/9
 **/
@Api( tags = "部门表数据修改对外接口" )
@Controller
@RequestMapping(value = "/admin")
public class DepartmentController {

    @Resource
    private DepartmentService departmentService;

    // 部门新增
    @ResponseBody
    @RequestMapping(value = "dept", method = RequestMethod.POST) // 如果@ResponseBody返回String，则需要加produces = "text/html;charset=UTF-8"
    @ApiOperation(value = "部门新增", notes = "使用URL传参")
    public JSONObject saveDept(@ApiParam(value = "部门名称", example = "计算机科学与工程系", required = true) @RequestParam("deptName") String departmentName){
        Department department = new Department();
        department.setDeptName(departmentName);
        return departmentService.saveDept(department);
    }

    // 部门删除
    @ResponseBody
    @RequestMapping(value = "dept", method = RequestMethod.DELETE)
    @ApiImplicitParams(
            @ApiImplicitParam(dataType="String", name = "请求载荷", value = "example as {\"deptId\":\"4E78FCF4B4CE469EBA28309F99602D20\"}", required = true, paramType = "body")
    )
    @ApiOperation(value = "部门删除", notes = "使用body传参")
    public JSONObject deleteDept(@ApiIgnore @RequestBody() Map<String, Object> requestBody){
        return departmentService.deleteDept(requestBody);
    }

    // 部门查询：下拉框专用
    @ResponseBody
    @RequestMapping(value = "dept", method = RequestMethod.GET)
    @ApiOperation(value = "部门查询", notes = "无需参数")
    public JSONObject queryListOfDeptName(){
        return departmentService.queryListOfDeptName();
    }

    // 部门修改
    @ResponseBody
    @RequestMapping(value = "dept", method = RequestMethod.PUT)
    @ApiOperation(value = "部门修改", notes = "使用body传参")
    public JSONObject updateDeptInfo(@RequestBody Map<String, Object> requestMap){
        return departmentService.updateDeptInfo(requestMap);
    }

    // 部门查询：分页查询，可根据名字模糊筛选
    @ResponseBody
    @RequestMapping(value = "deptQuery", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    @ApiOperation(value = "部门分页查询", notes = "使用body传参")
    public JSONObject queryListOfDept(@RequestBody Map<String, Object> map){
        return departmentService.queryDept_Paging(map);
    }

}
